﻿Public Class Form1
    Dim sec As Integer = 0
    Dim min As Integer = 0
    Dim hor As Integer = 1
    Dim fhor As Integer = 0
    Dim button As Integer
    Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Timer1.Stop()
        If MessageBox.Show("終了しますか？", "メッセージ", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.No Then
            e.Cancel = True
        End If
        Timer1.Start()
    End Sub

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

        Button6.Text = "START"
        Button7.Text = "EXIT"


    End Sub


    Private Sub Button7_Click(sender As System.Object, e As System.EventArgs) Handles Button7.Click
        If Button7.Text = "EXIT" Then
            End
        End If
    End Sub

    Private Sub Button6_Click(sender As System.Object, e As System.EventArgs) Handles Button6.Click

        If Button6.Text = "START" Then
            Timer1.Start()
            min = 0
            sec = 0
            hor = 0
            fhor = 0
            Label1.Text = "経過時間: 0 分 0 秒"
            Dim random As New Random
            Dim a As Integer = 0
            Dim i As Integer = 0
            Dim f As Integer = 0
            Dim flg(15) As Integer
            Dim num(15) As Integer
            While (i < 16)
                a = random.Next(0, 16)
                If flg(a) = 0 Then
                    If a = 15 Then
                        f = i
                    Else
                        num(i) = a + 1
                    End If
                    flg(a) = 1
                    i = i + 1
                End If
            End While

            Dim test As Integer

            For test = 1 To 16
                If num(test - 1) = 0 Then
                    Me.Controls("Button" & test).Text = ""
                Else
                    Me.Controls("Button" & test).Text = CStr(num(test - 1))
                End If
            Next



        End If
    End Sub

    Private Sub 終了ToolStripMenuItem1_Click(sender As System.Object, e As System.EventArgs) Handles 終了ToolStripMenuItem1.Click
        Me.Close()
    End Sub

    Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
        If fhor = 0 Then

            sec = sec + 1
            If sec = 60 Then
                min = min + 1
                sec = 0
            End If
            Label1.Text = "経過時間: " & min & " 分 " & sec & " 秒"
            If min = 60 Then
                min = 0
                fhor = 1
            End If
        Else
            sec = sec + 1
            If sec = 60 Then
                min = min + 1
                sec = 0
            End If
            If min = 60 Then
                hor = hor + 1
                min = 0
            End If
            Label1.Text = "経過時間: " & hor & " 時間 " & min & " 分"
        End If
    End Sub
    Private Sub Button_click(sender As System.Object, e As System.EventArgs) Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click, Button5.Click, Button6.Click, Button7.Click, Button8.Click, Button9.Click, Button10.Click, Button11.Click, Button12.Click, Button13.Click, Button14.Click, Button15.Click, Button16.Click
        Dim i As Integer
        Dim temp As String
        For i = 1 To 16
            If Me.Controls("Button" & i).Focused = True Then
                button = Me.Controls("Button" & i).TabIndex
            End If
        Next

    End Sub
End Class
